<template>
	<view class="goods_list_page">
		<goods-list :goods="goods"></goods-list>
		<view class="is_over" v-if="isOver">----我是有底线的---</view>
	</view>
</template>

<script>
	import goodsList from "../../components/goods-list/goods-list.vue"
	export default {
		data() {
			return {
				pagenum: 1,
				goods: [],
				isOver: false,
				cid: ''
			}
		},
		components: {
			"goods-list": goodsList,
		},
		methods: {
			//获取商品列表数据
			async getGoodsList() {
				const res = await this.$myRequest({
					url: '/goods/search?pagenum=' + this.pagenum + '&cid=' + this.cid
				})
				console.log(res)
				uni.stopPullDownRefresh();
				if (res.data.message.goods.length < 10) {
					return this.isOver = true
				}
				this.goods = [...this.goods, ...res.data.message.goods]
			}
		},
		onLoad(option) {
			console.log(option)
			this.cid = option.cid
			this.getGoodsList()
		},
		onReachBottom() {
			console.log('触底了')
			this.pagenum++
			this.getGoodsList()
		},
		onPullDownRefresh() {
			console.log('下拉刷新')
			this.pagenum = 1
			this.goods = []
			this.getGoodsList()
		}
	}
</script>

<style lang="scss">
	.goods_list_page {
		background: $shop-color-bg;

		.is_over {
			text-align: center;
			width: 100%;
			height: 50rpx;
			text-align: 50rpx;
		}
	}
</style>
